import $ from 'jQuery';
(function () {
    let $tree = null;
    let $vue = new Vue({
        el: '.function-permission-main-hook',
        data: {
            leaseType: [{id: 1, name: '短租'}, {id: 2, name: '长租'}],
            receiveStatus:[{id: 1, name: '部分收货'}, {id: 2, name: '全部收货'},{id: 3, name: '订单取消'}],
            orderStatus  : [{id: 0, name: '未审核'}, {id: 1, name: '已审核'}, {id: 2, name: '已完结'}, {id: 3, name: '已废弃'}],
            paymentFlag:[{id:1,name:'未打款'},{id:2,name:'已打款至第三方银行'},{id:3,name:'已收款'}],
            boxs: {
                box1: {show: true, hook: '.box1-hook', lock: true, url: '', params: {}},
                box2: {show: false, hook: '.box2-hook', url: '', params: {}},
                box3: {show: false, hook: '.box3-hook', url: '', params: {}},
                box4: {show: false, hook: '.box4-hook', url: '', params: {}}
            },
            roleList: []
        },
        created: function () {
            M.Request.getRoleList(true, (roleList, ret) => {
                this.roleList = roleList;
            });
            /*树菜单*/
            let setting = {
                check: {
                    enable: true
                },
                data: {
                    simpleData: {
                        enable: true,
                        idKey: 'id',
                        pIdKey: 'pid',
                        rootPId: 0,
                    }
                },
                callback: {
                    onCheck:function zTreeOnCheck(event, treeId, treeNode){
                        console.log(treeNode);
                    }
                }
            };
            IOT.getServerData(URI.SYSTEM.FUNCTION.TREE, {}, (ret) => {
                if (ret.code === 200) {
                    let treeList = ret.data;
                    $tree = $.fn.zTree.init($('#function_permission_tree'), setting, treeList);
                    $tree.expandAll(true);
                } else {
                    IOT.tips(ret.msg, 'error');
                }
            });
        },
        methods: {
            emitPage: function () {
                M.Page.load(this.boxs);
            },
            // 上一页
            prePage: function () {
                M.Page.prePage(this.boxs);
            },
            // 触发刷新页(当前显示的页面)
            refreshPage: function () {
                M.Page.refreshPage(this.boxs);
            },
            // 分配权限
            permission: function () {
                
            }
        },
        mounted: function () {
            let thiz = this;
            this.$nextTick(() => {
                let tableHookName = '.function-permission-table-hook';
                let $accountBox = $('.function-permission-hook');
                var $form = $accountBox.find('.form-hook');
                // 查询
                $form.off('submit').on('submit', function () {
                    $(tableHookName).bootstrapTable('onCustomSearch');
                    return false;
                });
                var $tableHook = $accountBox.find(tableHookName).bootstrapTable({
                    scrollbar: 'function-permission-table-body',
                    striped: true, // 设置为 true 会有隔行变色效果
                    pagination: true, // true 显示分页
                    paginationDetail: true, // 分页详情
                    sidePagination: 'server', // 服务器端
                    method: 'post',
                    url: URI.SYSTEM.FUNCTION.LIST,
                    debug: false,
                    cache: false,
                    pageNumber: 1,
                    pageSize: 20,
                    pageList: [10, 20, 50, 100],
                    // fixedColumns: true,
                    customButton: '',
                    customQueryParams: function (params) {
                        var formParams = $form.serializeJson();
                        var queryParams = $.extend({}, params, formParams);
                        //console.log(queryParams);
                        return queryParams;
                    },
                    onLoadSuccess: function (data) {
                        //console.log(JSON.stringify(data));
                    },
                    onLoadError: function (status, xhr) {
                    },
                    onCheckAll: function (rows) {
                        
                    },
                    columns: [
                        {
                            field: '', radio: true, align: 'center', fixedLeft: true, width: 60,
                            events: {
                                'change .radio-hook': function (e, value, row, index) {
                                    //console.log('单选框: ' + value);
                                }
                            }
                        },
                        {
                            field: 'mobile', title: '角色编码', align: 'center', fixedLeft: true,tips:true
                        },
                        {
                            field: 'userName', title: '角色名称', align: 'center', fixedLeft: true,tips:true
                        },
                        {
                            field: 'gender', title: '用户数量', align: 'center', fixedLeft: true,width:80,
                        },
                        {
                            field: 'companyName', title: '角色备注', align: 'center', fixedLeft: true,tips:true
                        }
                    ]
                });
            });
        }
    });
})();